package cn.yunlang.zhangZhongFei.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import cn.yunlang.zhangZhongFei.entity.WinAward;
import cn.yunlang.zhangZhongFei.service.ExchangeAwardService;
import cn.yunlang.zhangZhongFei.service.WinAwardService;
import cn.yunlang.zhangZhongFei.util.JwtUtil;
import cn.yunlang.zhangZhongFei.vo.request.ExchangeAwardVo;
import cn.yunlang.zhangZhongFei.vo.request.TokenRequest;
import cn.yunlang.zhangZhongFei.vo.response.R;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/WinAward")
@Api(tags = "中奖记录")
public class WinAwardController {

  @Resource private WinAwardService winAwardService;

  @Resource private ExchangeAwardService exchangeAwardService;

  //    @ApiOperation("全查")
  //    @GetMapping("/list")
  //    public R<List<WinAward>> list() {
  //        return R.success(winAwardService.list());
  //    }

  @ApiOperation("分页查")
  @GetMapping("/page")
  public R<IPage<WinAward>> page(
      @RequestParam Integer pageNo,
      @RequestParam Integer pageSize,
      @RequestBody TokenRequest request) {
   
    return winAwardService.pageWinAward(pageNo, pageSize, Long.valueOf(new JwtUtil().getUserId()));
  }

  @GetMapping("/one")
  @ApiOperation("根据Id查一条")
  public R<WinAward> one(@RequestParam Long winAwardId) {
    return winAwardService.getOne(winAwardId);
  }

  @PostMapping("/exchange")
  @ApiOperation("兑奖")
  public R<String> exchange(
      @RequestBody ExchangeAwardVo exchangeAwardVo) {
   
    exchangeAwardVo.setUserId(Long.valueOf(new JwtUtil().getUserId()));
    return winAwardService.exchange(exchangeAwardVo);
  }

  @PostMapping("/add")
  @ApiOperation("新增")
  public R<String> add(@RequestBody WinAward winAward) {
   
    winAward.setUserId(Long.valueOf(new JwtUtil().getUserId()));
    return winAwardService.addWinAward(winAward);
  }

  @GetMapping("/delete")
  @ApiOperation("删除")
  public R<String> delete(@RequestParam Long winAwardId) {
    return winAwardService.deleteWinAward(winAwardId);
  }

  @PostMapping("/update")
  @ApiOperation("修改")
  public R<String> update(@RequestBody WinAward winAward) {
   
    winAward.setUserId(Long.valueOf(new JwtUtil().getUserId()));
    return winAwardService.updateWinAward(winAward);
  }
}
